//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;

namespace STT.Business
{
    public class BTbMaNgachLuong
    {
        public static DataTable Search(ETbMaNgachLuong mnl)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaNL", mnl.TenNL);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbMaNgachLuong_Search", pr);
            return all;
        }
       
        public static bool KiemTraDuLieu(ETbMaNgachLuong mnl)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenNL", mnl.TenNL);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbMaNgachLuong_KiemTraDuLieu", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        public static bool KiemTraDuLieu_Sua(ETbMaNgachLuong mnl)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"TenNL", mnl.TenNL);
            pr[1] = new SqlParameter(@"MaNL", mnl.MaNL);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbMaNgachLuong_KiemTraDuLieu_Sua", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        //-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbMaNgachLuong_SelectAll", null);
            return all;
        }
        public static DataTable LoadDropdownlist(int MaNhomNL)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaNhomNL", MaNhomNL);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbMaNgachLuong_LoadDropdownlist", pr);
            return all;
        }
        //-----------------------------------------------------------//
        public static void Insert(ETbMaNgachLuong OTbMaNgachLuong)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaNL", OTbMaNgachLuong.MaNL);
            pr[1] = new SqlParameter(@"TenNL", OTbMaNgachLuong.TenNL);
            pr[2] = new SqlParameter(@"MaNhomNL", OTbMaNgachLuong.MaNhomNL); 
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbMaNgachLuong_Insert", pr);
        }
        //-----------------------------------------------------------//
        public static void Update(ETbMaNgachLuong OTbMaNgachLuong)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaNL", OTbMaNgachLuong.MaNL);
            pr[1] = new SqlParameter(@"TenNL", OTbMaNgachLuong.TenNL);
            pr[2] = new SqlParameter(@"MaNhomNL", OTbMaNgachLuong.MaNhomNL);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbMaNgachLuong_Update", pr);
        }
        //-----------------------------------------------------------//
        public static void Delete(string MaNL)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaNL", MaNL);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbMaNgachLuong_Delete", pr);
        }
        //-----------------------------------------------------------//
        public static ETbMaNgachLuong SelectByID(string MaNL)
        {
            ETbMaNgachLuong OTbMaNgachLuong = new ETbMaNgachLuong();
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaNL", MaNL);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbMaNgachLuong_STenNLelectByID", pr);
            if (idr.Read())
                OTbMaNgachLuong = GetOneTbMaNgachLuong(idr);
            idr.Close();
            idr.Dispose();
            return OTbMaNgachLuong;
        }
        //-----------------------------------------------------------//
        private static ETbMaNgachLuong GetOneTbMaNgachLuong(IDataReader idr)
        {
            ETbMaNgachLuong OTbMaNgachLuong = new ETbMaNgachLuong();
            if (idr["MaNL"] != DBNull.Value)
                OTbMaNgachLuong.MaNL = (string)idr["MaNL"];
            if (idr["TenNL"] != DBNull.Value)
                OTbMaNgachLuong.TenNL = (string)idr["TenNL"];
            return OTbMaNgachLuong;
        }
        //-----------------------------------------------------------//
        public static bool TestByID(string MaNL)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaNL", MaNL);
            pr[1] = new SqlParameter(@"TestID", SqlDbType.Bit);
            pr[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbMaNgachLuong_TestByID", pr);
            return Convert.ToBoolean(pr[1].Value);
        }
        //-----------------------------------------------------------//
        public static List<ETbMaNgachLuong> ListAll()
        {
            List<ETbMaNgachLuong> list = new List<ETbMaNgachLuong>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbMaNgachLuong_SelectAll", null);
            while (idr.Read())
                list.Add(GetOneTbMaNgachLuong(idr));
            if (idr.IsClosed == false)
            {
                idr.Close();
                idr.Dispose();
            }
            return list;
        }
    }

}
